package model.stageOfGame;

import java.util.HashMap;
import java.util.Map;

import model.conversations._ConversationManager;
import model.locations._World;
import model.stageOfGame.ConversationSuccessStage;
import model.stageOfGame.ObtainItemStage;
import model.stageOfGame.Stage;


public class StageManager {

	
	//this hashMap stores all the levels or stages in the game denoted by an integer
	//starting with with 1 and going upwards
	Map<String,Stage> stagesInGame= new HashMap<String,Stage>();
	
	char stage='a';
	int level=1;
	
	
	public StageManager(_ConversationManager convManager, _World world){
		
		//here we put new stage critera into the game. 
		//In order to progress to the next stage has the previous stage needs to be completed
		stagesInGame.put("1b",new ConversationSuccessStage(world,convManager,"convince Saul to let you join the expedition","SAUL"));
	}
	
	//this method checks to see whether the person is allowd to change area
	//the person is only allowed to change area when he has completed certain stages
	public boolean changeSetting(){
	
		String key =String.valueOf(level)+(char)(stage+1);
		//below makes sure that this is the last stage in the level
		if(!stagesInGame.containsKey(key)){
				level+=1;
				return true;
		}
		
		return false;
	}
	
	public String getObjective(){
		String key =String.valueOf(level)+(char)(stage+1);
		if(stagesInGame.containsKey(key))
		return stagesInGame.get(key).getDescription();
		return "you have completed all the objectives for this level";
	}
	
// I like this bit of code even if I say so	myself!
//this method is called after every iteration in go() (quite often) to see if stage has been completed
	public char updateCurrentStage(){
		//update stage only if the stage is not the last stage in a level
		String key =String.valueOf(level)+(char)(stage+1);
		//System.out.println("key"+key);
		if(stagesInGame.containsKey(key)){
			if(stagesInGame.get(key).isStageComplete()){
				stage+=1;
			return stage;
			}
		}
		return stage;
	}
	
	public int getLevel(){
		return level;
	}
}
